package main

import (
	"goweb2/config"
	"goweb2/internal/model"
	"goweb2/internal/routes"
	"goweb2/pkg/db"

	"github.com/gofiber/fiber/v2"
)

func main() {
	cfg := config.Load()

	// 初始化数据库
	if err := db.InitPostgres(cfg); err != nil {
		panic("❌ Failed to connect to database: " + err.Error())
	}

	// 迁移数据表
	db.DB.AutoMigrate(&model.User{})

	app := fiber.New()

	routes.SetupRoutes(app, cfg.JWTSecret)

	app.Listen(":" + cfg.Port)
}
